import { observable, action } from 'mobx';
import { productSubs } from '../fetch/apisetting';


class ProductModule {
    @observable ProductListData = [];
    @observable ProductDetail = {};
    @observable orderStatus=1;
    @observable tableData=[];
    @observable ProductListDataAll=[];
    @observable param={
        getProductList:{
            "type":"0",
            "status":"1"
       },
       ProductDetailId:{
           "id":"0",
       },
       productSubscription:{
           "id":JSON.parse(localStorage.getItem('userData'))?JSON.parse(localStorage.getItem('userData')).id:361,
       }
    }
    @action getProductList(){
        return productSubs.getProductList(this.param.getProductList).then(
            action('getProductList',res=>{
                window.success(res.errormsg)
                this.ProductListDataAll=this.ProductListData=res.data.list;
                this.param.ProductDetailId.id=res.data.list[0].id;
                this.getInterfaceConfigList()
            })
        )
    }
     @action productSubscription(){
    return productSubs.productSubscription(Object.assign(this.param.productSubscription,{productId:this.param.ProductDetailId.id})).then(
        action('productSubscription',res=>{
            window.success(res.errormsg)

})
)
}
    @action productUnSubscription(){
    return productSubs.productUnsubscription(Object.assign(this.param.productSubscription,{productId:this.param.ProductDetailId.id})).then(
        action('productUnSubscription',res=>{
            window.success('退订成功')

})
)
}
    @action getProductDetail(){
    return productSubs.getProductDetail(this.param.ProductDetailId).then(
        action('getProductList',res=>{
            console.log(res.data);
            this.ProductDetail=res.data;
            this.orderStatus=res.data.orderStatus

        })
    )
}
    @action getInterfaceConfigList(){
        return productSubs.getInterfaceConfigList(this.param.ProductDetailId).then(
            action('getInterfaceConfigList',res=>{
                window.success(res.errormsg)
                this.tableData=res.data

            })
        )
    }

}

export default new ProductModule();
